package cmd

import (
	"context"
	"video-api/utility/redis_client"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
	"github.com/hibiken/asynq"
	"github.com/hibiken/asynqmon"
)

var (
	Asynqmon = &gcmd.Command{
		Name:        "asynqmon",
		Brief:       "start asynqmon server",
		Description: "this is the command entry for starting all server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server("asynqmon")
			h := asynqmon.New(asynqmon.Options{
				RootPath:     "/",
				RedisConnOpt: asynq.RedisClientOpt{Addr: redis_client.RedisConfigDefault.Addr, Password: redis_client.RedisConfigDefault.Password, DB: 1},
			})
			s.Group("/monitoring", func(group *ghttp.RouterGroup) {
				group.ALL("/", func(r *ghttp.Request) {
					h.ServeHTTP(r.Response.Writer, r.Request)
				})
			})
			s.Run()
			return nil
		},
	}
)
